package com.lwt.yygh.common.exception;

import com.lwt.yygh.common.result.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Author Weton Li
 * @Date 2021/4/7 12:18
 */
@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result error(Exception exception){
        exception.printStackTrace();
        return Result.fail();
    }

    /**
     * 自定义异常类 出现异常时的返回json信息
     * @param yyghException
     * @return
     */
    @ExceptionHandler(YyghException.class)
    @ResponseBody
    public Result error(YyghException yyghException){

        return Result.build(yyghException.getCode(),yyghException.getMessage());

    }

}
